//var e=getEvent();
//var jq = jQuery.noConflict();
//window.onbeforeunload=function(){ws.send("Logout");}

function getId(id)
{
    return document.getElementById(id);
}
function Datetime(tag)
{
    return new Date().toTimeString().split(' ')[tag];
}
function SetChatValue(Variables, value)
{
    ChatValue[Variables] = value;
}
function GetChatValue(Variables)
{
    return ChatValue[Variables];
}

var ChatValue = new Array(10);
function SwfloadCompleted(tag)
{
    if (tag == 'Video_main')
    {
        VideoLoaded = true;
        if (RoomInfo.type == '0')
        {
            getId('RoomMV').style.display = 'none';

        }
        else
        {
            if (RoomInfo.AutoPublicVideo == '1') {
                if (RoomInfo.PVideo == My.chatid)
                    thisMovie('pVideo').sConnect(RoomInfo.VServer, My.rid + '·' + My.chatid, '1');
                else
                    thisMovie('pVideo').pConnect(RoomInfo.VServer, My.rid + '·' + RoomInfo.PVideo, RoomInfo.PVideoNick);
            }
            if (RoomInfo.AutoSelfVideo == '1') {
                if (RoomInfo.PVideo == My.chatid)
                    thisMovie('pVideo').sConnect(RoomInfo.VServer, My.rid + '·' + My.chatid, '1');
                else
                    thisMovie('pVideo').sConnect(RoomInfo.VServer, My.rid + '·' + My.chatid, '2');
            }
        }
    }
}
function showLive() {
    if (RoomInfo.OtherVideoAutoPlayer == '0') {
        location.reload();
    }
    $('#OnLine_MV').html($('#OnLine_MV').html());
}
var socket;
var page_fire;
function OnSocket() {
    connect();


    // socket.on('message', function(data) {
    //     WriteMessage(data);
    // });
    // onmessage();
}

function OnInit()
{
    if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style)
    {
        location.href = 'error.php?msg=' + encodeURIComponent('您使用的是不安全IE6.0浏览器,请升级到最新版本或<br>下载安装<a href=http://chrome.360.cn/ target=_blank>360浏览器</a>或<a href=http://www.baidu.com/s?wd=chrome target=_blank>Google浏览器</a>!');
        return false;
    }
    $.ajaxSetup({contentType: "application/x-www-form-urlencoded; charset=utf-8"});

    $("body").click(function() {
        MsgCAlert();
    });


     win_marginleft = check_auth("room_admin")?213:10;
    //auth
    if (check_auth("room_admin")){
        $('#manage_div').show();
        $('#OnlineUser_Find').show();
        $('#UI_Right').show();
    }



    //发送自定义聊天图片
    if (check_auth("custom_pic")){
        $('.chat_img').show();
        $('#OnlineUser_Find').show();
    }

    if (check_auth("rebots_msg"))
        $('#chat_type').show();
    if (check_auth("def_videosrc"))
        $('#bt_defvideosrc').show();

    if (check_auth("online_sum"))
        $('#onlineWrap').show();

    if (check_auth("room_admin"))
        $('#RealWrap').show();

    OnSocket();

    //5分钟提示登录
    if (RoomInfo.loginTip == '1' && My.chatid.indexOf('x') > -1)
        //setInterval("loginTip()", 1000 * 60 * 5);

    $('#Msg').html("连接中...");
    MsgAutoScroll();

    window.moveTo(0, 0);
    window.resizeTo(screen.availWidth, screen.availHeight);
    OnResize();

    if (RoomInfo.OtherVideoAutoPlayer != "0") {
        $('#OnLine_MV').html('<iframe height="100%" width="100%" allowTransparency="true" marginwidth="0" marginheight="0"  frameborder="0" scrolling="no" src="player.php?type=pc&rid='+globalgid+'"></iframe>');
    } else {
        var vFlash = new SWFObject("images/Video_main.swf?Q=" + RoomInfo.VideoQ, "pVideo", "520", "390", "9", "#FFF");
        vFlash.addParam("wmode", "transparent");
        vFlash.addParam("allowFullScreen", "true");
        vFlash.addParam("allowScriptAccess", "always");
        vFlash.write("OnLine_MV");
    }

    interfaceInit();
    POPChat.Init();
    ToUser.set('ALL', '大家');
    dragMsgWinx(getId('drag_bar'));
    $('#MsgBox1').niceScroll({cursorcolor: "#FFF", cursorwidth: "2px", cursorborder: "0px;"});
    $('#MsgBox2').niceScroll({cursorcolor: "#FFF", cursorwidth: "2px", cursorborder: "0px;"});
    $('#OnLineUser_FindList').niceScroll({cursorcolor: "#FFF", cursorwidth: "2px", cursorborder: "0px;"});
    $('#OnLineUser_OhterList').niceScroll({cursorcolor: "#FFF", cursorwidth: "2px", cursorborder: "0px;"});
    $('#OnLineUser').niceScroll({cursorcolor: "#FFF", cursorwidth: "2px", cursorborder: "0px;"});

    //定位div(contenteditable = "true")
    function po_Last_Div(obj) {
        if (window.getSelection) {//ie11 10 9 ff safari
            obj.focus(); //解决ff不获取焦点无法定位问题
            var range = window.getSelection();//创建range
            range.selectAllChildren(obj);//range 选择obj下所有子内容
            range.collapseToEnd();//光标移至最后
        }
        else if (document.selection) {//ie10 9 8 7 6 5
            var range = document.selection.createRange();//创建选择对象
            //var range = document.body.createTextRange();
            range.moveToElementText(obj);//range定位到obj
            range.collapse(false);//光标移至最后
            range.select();
        }
    }

    $("#Msg").keydown(function(e) {
        if (e.keyCode == 13) {
            msg_send();
            return false;
        }
    });

    initFaceColobar();

    $(".gift_close").click(function() {
        $(".giftList").hide();
        return false;
    });
    $(".GetFolowers").click(function() {
        $(".giftList").toggle();
    });

}

function OnResize() {

    win_marginleft = check_auth("room_admin")?213:10;

    var cw = $(window).width();
    var cH = $(window).height();
    var vw = cw - 930;
    if (cw >= 1280) {
        if (cw >= 1280)
            vw = cw - 725;
        if (cw >= 1400)
            vw = cw - 800;
        if (cw >= 1600)
            vw = cw - 930;
        if (vw > 520) {
            $('#UI_Left').css("margin-left", win_marginleft);//242 + 5原来的尺寸
            $('#UI_Left').css("margin-right", 365);
            //$('#UI_Right').css("width", vw);
            $('#OnLine_MV').css("height", cH-260);
        }
		/*var c_w = 242 * 1000 / 378;
		var r_w = cw - (242 + c_w) - 10;
		$('#UI_Right').css("width", r_w);
		$('#OnLine_MV').css("height", r_w / 1000 * 618);
		$('#UI_Central').css("margin-left", 242 + 5);
		$('#UI_Central').css("margin-right", r_w + 10);
		//console.log(c_w);
		//console.log(r_w);*/
    } else {
        $('#UI_Left').css("margin-left", win_marginleft);
        $('#UI_Left').css("margin-right", "365px");
        //$('#UI_Right').css("width", 520);
        //$('#OnLine_MV').css("height", 520 / 1000 * 618);

            $('#OnLine_MV').css("height", cH-260);
    }

    var cH = $(window).height() - 13;
    $('#UI_MainBox').height(cH);
    $('#MsgBox1').height($('#MsgBox1').height() + cH - $('#UI_Central').height() - $('#UI_Head').height());

    $('#OnLineUser').height($('#OnLineUser').height() + $('#UI_Central').height() - $('#UI_Left2').height()+90);
    $('#UI_Left1').height($('#UI_Left2').height());
    // $('#NoticeList').height($('#NoticeList').height() + $('#UI_Central').height() - $('#UI_Right').height());

    $("#OnLineUser_OhterList").height($('#OnLineUser').height());
    $("#OnLineUser_FindList").height($('#OnLineUser').height());
}
function OnUnload() {
    var str = "Logout=M=";
    socket.emit('message', str);
}
function tCam(tag)
{
    My.cam = tag;
}
function tCamState(tag)
{
    My.camState = tag;
}

function h_l(e)
{
    if (getId('UI_Left').style.display == '')
    {
        getId('UI_Left').style.display = 'none';
        getId('UI_Central').style.marginLeft = '2px';
        e.src = "images/h_r.gif";
    }
    else
    {
        getId('UI_Left').style.display = '';
        getId('UI_Central').style.marginLeft = '157px';
        e.src = "images/h_l.gif";
    }
    getId('FontBar').style.display = 'none';
}
function h_r(e)
{
    if (getId('UI_Right').style.display == '')
    {
        getId('UI_Right').style.display = 'none';
        getId('UI_Central').style.marginRight = '2px';
        e.src = "images/h_l.gif";
    }
    else
    {
        getId('UI_Right').style.display = '';
        getId('UI_Central').style.marginRight = '248px';
        e.src = "images/h_r.gif";
    }
    getId('FontBar').style.display = 'none';
}
function getXY(obj)
{
    var a = new Array();
    var t = obj.offsetTop;
    var l = obj.offsetLeft;
    var w = obj.offsetWidth;
    var h = obj.offsetHeight;
    while (obj = obj.offsetParent)
    {
        t += obj.offsetTop;
        l += obj.offsetLeft;
    }
    a[0] = t;
    a[1] = l;
    a[2] = w;
    a[3] = h;
    return a;
}


function CloseColorPicker()
{
    getId('ColorTable').style.display = 'none'
}

function ck_Font(e, act)
{
    if (e != null)
    {
        e.value == 'true' ? e.value = 'false' : e.value = 'true';
    }
    switch (act)
    {
        case 'FontBold':
            if (e.value == 'true')
                getId('Msg').style.fontWeight = 'bold';
            else
                getId('Msg').style.fontWeight = '';
            break;
        case "FontItalic":
            if (e.value == 'true')
                getId('Msg').style.fontStyle = 'italic';
            else
                getId('Msg').style.fontStyle = '';
            break;
        case 'Fontunderline':
            if (e.value == 'true')
                getId('Msg').style.textDecoration = 'underline';
            else
                getId('Msg').style.textDecoration = '';
            break;
        case 'FontColor':
            getId('Msg').style.color = getId('ColorShow').style.backgroundColor;
            break;
        case 'ShowColorPicker':
            bt_ColorPicker();
            break;
    }
}
function ColorPicker()
{
    var baseColor = new Array(6);
    baseColor[0] = "00";
    baseColor[1] = "33";
    baseColor[2] = "66";
    baseColor[3] = "99";
    baseColor[4] = "CC";
    baseColor[5] = "FF";
    var myColor;
    myColor = "";
    var myHTML = "";
    myHTML = myHTML + "<div style='WIDTH:180px;HEIGHT:120px;' onclick='ck_Font(null,\"FontColor\");CloseColorPicker()'>";
    for (i = 0; i < 6; i++)
    {
        for (j = 0; j < 3; j++)
        {
            for (k = 0; k < 6; k++)
            {
                myColor = baseColor[j] + baseColor[k] + baseColor[i];
                myHTML = myHTML + "<li data=" + myColor + " onmousemove=\"document.getElementById('ColorShow').style.backgroundColor=this.style.backgroundColor\" style='background-color:#" + myColor + "'></li>";
            }
        }

    }
    for (i = 0; i < 6; i++)
    {
        for (j = 3; j < 6; j++)
        {
            for (k = 0; k < 6; k++)
            {
                myColor = baseColor[j] + baseColor[k] + baseColor[i];//get   Color
                myHTML = myHTML + "<li data=" + myColor + " onmousemove=\"document.getElementById('ColorShow').style.backgroundColor=this.style.backgroundColor\" style='background-color:#" + myColor + "'></li>";
            }
        }
    }

    myHTML = myHTML + "</div><div style='border:0px; width:180px; height:10px; background:#333333' id='ColorShow'></div>";
    document.getElementById("ColorTable").innerHTML = myHTML;
}
var ColorInit = false;
function bt_ColorPicker()
{
    var t = getXY(getId('FontColor'));
    getId('ColorTable').style.top = t[0] - 145 + 'px';
    getId('ColorTable').style.left = t[1] + 1 + 'px';
    if (!ColorInit)
    {
        ColorPicker();
        ColorInit = true;
    }
    getId('ColorTable').style.display = '';
    getId('ColorTable').focus();
    return true;

}

function bt_Personal(e)
{
    if (e.value == 'false')
    {
        e.value = 'true';
        e.src = "images/Personal_true.gif";
        e.title = '私聊中...[公聊/私聊]';
    }
    else
    {
        e.value = 'false';
        e.src = "images/Personal_false.gif";
        e.title = '公聊中...[公聊/私聊]';
    }
}
function bt_FontBar(e)
{
    if (getId('FontBar').style.display == 'none')
    {
        var t = getXY(getId('UI_Control'));
        getId('FontBar').style.display = '';
        //getId('FontBar').style.top = t[0] - 29 + 'px';
        //getId('FontBar').style.left = isIE ? t[1] + 1 : t[1] + 'px';
        getId('FontBar').style.top = '0px';
        getId('FontBar').style.left = '0px';
        getId('FontBar').style.width = t[2] - 8 + 'px';
    }
    else
    {
        getId('FontBar').style.display = 'none';
    }
}
function bt_Send_key_option(e)
{
    var t = getXY(e);
    getId('Send_key_option').style.top = t[0] - 50 + 'px';
    getId('Send_key_option').style.left = t[1] + 2 - 165 + 'px';
    getId('Send_key_option').style.display = '';
    getId('Send_key_option').focus();
}



function InsertImg(id, src) {
    $(id).append('<img src=\"' + src + '\">');
}
function bt_insertImg(id)
{
    $('#imgUptag').val(id);
    $('#filedata').click();
}
function bt_gifts(e) {
    openWithIframe('送礼物', '../glist_room.php', 300, 405, '', true)
}
function bt_MsgClear() {
    getId('MsgBox1').innerHTML = '';
    getId('MsgBox2').innerHTML = '';
}
function bt_SendEmote(obj) {
    getId('Msg').innerHTML = obj.innerHTML;
    SysSend.msg();
    getId('Emote').style.display = 'none';
}
function bt_SwitchListTab(tag) {

    if (tag == 'User') {
        $("#OnLineUser_OhterList").hide();
        $("#OnLineUser_FindList").hide();
        $("#OnLineUser").show();
        $("#listTab1")[0].className = 'bg_png2';
        $("#listTab2")[0].className = '';
    }
    else if (tag == "Other") {
        $("#OnLineUser_OhterList").show();
        $("#OnLineUser_FindList").hide();
        $("#OnLineUser").hide();
        $("#listTab1")[0].className = '';
        $("#listTab2")[0].className = 'bg_png2';
        UserList.getmylist(My.name);
    }
    return false;
}
function bt_defvideosrc() {
    if (check_auth('def_videosrc')) {
        SysSend.command('setVideoSrc', My.chatid + '_+_' + My.nick);
        $.ajax({type: 'get', url: '../ajax.php?act=setdefvideosrc&vid=' + encodeURIComponent(My.chatid) + '&nick=' + encodeURIComponent(My.nick) + '&rid=' + My.rid});
    }
}
function bt_msgBlock(id) {
    SysSend.command('msgBlock', id);
}
function bt_msgAudit(id, a) {
    SysSend.command('msgAudit', id);
    $(a).hide();
}
function bt_FindUser() {
    getId("OnLineUser_OhterList").style.display = "none";
    var username = getId('finduser').value;
    getId("OnLineUser_FindList").style.display = "none";
    getId("OnLineUser").style.display = "";
    //alert(username);
    if (username == "") {
        getId("OnLineUser_FindList").style.display = "none";

        getId("OnLineUser").style.display = "";
    }
    else {
        getId("OnLineUser_FindList").style.display = "";
        getId("OnLineUser_FindList").innerHTML = "";
        getId("OnLineUser_FindList").style.height = getId("OnLineUser").offsetHeight + 'px';
        getId("OnLineUser").style.display = "none";

        var ulist = UserList.List();
        var li = "";
        for (c in ulist) {
            if (ulist[c].nick.toLowerCase().indexOf(username.toLowerCase()) >= 0) {
                //alert(ulist[c].nick);
                li = getId(ulist[c].chatid);
                var t_li = CreateElm(getId("OnLineUser_FindList"), 'li', false, 'fn' + ulist[c].chatid);
                t_li.innerHTML = li.innerHTML;
                t_li.oncontextmenu = li.oncontextmenu;
                t_li.onclick = li.onclick;
                t_li.ondblclick = li.ondblclick;
            }
        }

        if(!t_li){
            $('#OnLineUser_FindList').html('<li id="fn1" style="width: 100%"><p style="line-height: 32px; text-align: center;width: 100%;margin: 0 auto;">搜索的用户不在线或者不存在</p></li>');
        }
    }
}
var fenping = true;

function bt_fenping() {
    if (fenping == true) {
        fenping = false;
        getId('drag_bar').style.display = "";
        getId('MsgBox2').style.display = "";
        getId('MsgBox2').style.height = 100 + 'px';
        getId('MsgBox1').style.height = getId('MsgBox1').offsetHeight - 100 - getId('drag_bar').offsetHeight + "px";
    } else {
        fenping = true;
        //getId('btfp').src = 'images/FP_false.gif';
        getId('MsgBox1').style.height = getId('MsgBox').offsetHeight + "px";
        getId('drag_bar').style.display = "none";
        getId('MsgBox2').style.display = "none";

    }
    MsgAutoScroll();
}
var audioNotify = true;
function bt_toggleAudio() {
    if (audioNotify == true) {
        audioNotify = false;
        getId('toggleaudio').src = 'images/Sc.gif';
    } else {
        audioNotify = true;
        getId('toggleaudio').src = 'images/So.gif';
    }
}
var toggleScroll = true;
function bt_toggleScroll()
{
    if ($("#bt_gundong").attr("select") == "true") {
        $("#bt_gundong").attr("select", "false");
        toggleScroll = false;
    }
    else {
        $("#bt_gundong").attr("select", "true");
        toggleScroll = true;
    }
}


$(function(){
    window.onresize = function(){
        var cw = $(window).width();
        var cH = $(window).height();

        var vw = cw - 930;
        if (cw >= 1280) {
            if (cw >= 1280)
                vw = cw - 725;
            if (cw >= 1400)
                vw = cw - 800;
            if (cw >= 1600)
                vw = cw - 930;
            if (vw > 520) {
                $('#UI_Left').css("margin-left", win_marginleft);
                $('#UI_Left').css("margin-right", 365);
                //$('#UI_Right').css("width", vw);
                //$('#OnLine_MV').css("height", vw / 1000 * 618);
                $('#OnLine_MV').css("height", cH-260);
            }
        } else {
            $('#UI_Left').css("margin-left", win_marginleft);
            $('#UI_Left').css("margin-right", "365px");
            //$('#UI_Right').css("width", 520);
            //$('#OnLine_MV').css("height", 520 / 1000 * 618);
            $('#OnLine_MV').css("height", cH-260);
        }

        var cH = $(window).height() - 13;
        $('#UI_MainBox').height(cH);
        $('#MsgBox1').height($('#MsgBox1').height() + cH - $('#UI_Central').height() - $('#UI_Head').height());

        $('#OnLineUser').height($('#OnLineUser').height() + $('#UI_Central').height() - $('#UI_Left2').height()+90);
        $('#UI_Left1').height($('#UI_Left2').height());

        $("#OnLineUser_OhterList").height($('#OnLineUser').height());
        $("#OnLineUser_FindList").height($('#OnLineUser').height());
    }
})

// 点赞
function sendFace(pos) {
    var iconUrl = ""
    if (pos == "0") {
        iconUrl = '<img src="/room/skins/chatimg/geili.gif" class="flower_png" border="0" alt="" height="20px;">';
    }
    if (pos == "1") {
        iconUrl = '<img src="/room/skins/chatimg/flower.png" class="flower_png" border="0" alt="" height="20px;">';
    }
    if (pos == "2") {
        iconUrl = '<img src="/room/skins/chatimg/guzhang.png" class="guzhang_png" border="0" alt="" height="20px;">';
    }
    if (pos == "3") {
        iconUrl = '<img src="/room/skins/chatimg/ding.png" class="ding_png" border="0" alt="" height="20px;">';
    }
    if (pos == "4") {
        iconUrl = '<img src="/room/skins/chatimg/zan_icon.png" class="zan_png" border="0" alt="" height="20px;">';
    }
    $('#Msg').html(iconUrl);
    msg_send();

}

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate =  date.getHours() + seperator2 + date.getMinutes() ;
    return currentdate;
}

//phpwebsocket
function connect() {
    // 创建websocket
    // ws = new WebSocket("ws://"+document.domain+":7272");
    ws = new WebSocket("ws://" + RoomInfo.TServer + ":" + RoomInfo.TSPort);
    // 当socket连接打开时，输入用户名
    ws.onopen = onopen;
    // 当有消息时根据消息类型显示不同信息
    ws.onmessage = onmessage;
    ws.onclose = function() {
        console.log("连接关闭，定时重连");
        connect();
    };
    ws.onerror = function() {
        console.log("出现错误");
    };
}

// 连接建立时发送登录信息
function onopen()
{
    name = My.nick;
    if(!name)
    {
        show_prompt();
    }

    if (typeof (UserList) != 'undefined') {
        UserList.init();
    }
    // 登录
    var login_data = '{"type":"login","client_name":"'+name.replace(/"/g, '\\"')+'","room_id":"'+My.roomid+'","uid":"'+My.chatid+'","color":"'+My.color+'","qx":"'+My.qx+'"}';
    console.log("websocket握手成功，发送登录数据:"+login_data);
    ws.send(login_data);
}

// 服务端发来消息时
function onmessage(e) {
    var data = eval("(" + e.data + ")");
    console.log(data);
    switch (data['type']) {
        // 服务端ping客户端
        case 'ping':
            ws.send('{"type":"pong"}');
            break;
            ;
        // 登录
        case 'login':
            var U = data;
            if (U.chatid == '-1' || U.chatid == '-2')
                return;
            var vip_msg = "到来";
            var date = Datetime(0);
            var str = '欢迎：' + U.nick + ' ' + date;
            if (My.chatid != U.chatid) {
                UserList.add(U.chatid, U);
            }
            var type = 0;
            if (U.chatid == My.chatid)
                type = 2;

            console.log(data['nick'] + "登录成功");
            break;
        // 异地登录
        case 'otherLogin':
            location.href = "error.php?msg=" + encodeURI('其他地方登录！请注意同一帐号不能两处登录、同一电脑不能两处打开房间！')
            break;
        // 登录-更新用户列表
        case 'initUserList':
            client_list = data['client_list'];
            flush_client_list();
            break;
        // 发言
        case 'say':
            var str = FormatMsg(data);
            if (!str) {
                return false;
            }
            var type = 0;
            if (!str)
                return;
            if (BList.isExist(data.ChatId))
                return;
            if (data.ToChatId == My.chatid) {
                type = 2;
                MsgAlert(0);
                if (audioNotify == true)
                    playSound('msg.mp3');
            }

            if (data.ChatId == My.chatid)
                type = 2;

            if (data.ToChatId == 'ALL') {
                if (data.ChatId == My.chatid)
                    type = 2;
                else
                    type = 0;
            }
            if (data.IsPersonal != 'true') {
                MsgShow(str, type);
            } else {
                if (data.ChatId == My.chatid) {
                    POPChat.newtab(UserList.get(data.ToChatId));
                }
                else {
                    POPChat.newtab(UserList.get(data.ChatId));
                }
                POPChat.showmsg(UserList.get(data.ChatId), UserList.get(data.ToChatId), "<font style='" + data.Style + "'>" + decodeURIComponent(data.Txt.str_replace()) + "</font>");
            }

            break;
        // 用户退出 更新用户列表
        case 'logout':
            var U = data;
            console.log('退出登录');
            console.log(data);
            if (U.chatid == '-1' || U.chatid == '-2')
                return;
            UserList.del(U.chatid, U);
            break;
        // 送礼物
        case 'send_gif':
            $('#gift_super').attr('data', 'skins/gift/' + data.data_str.gift_id + '_188.swf');
            $('#gifcontainer').show();
            rideHorse(data.data_str.nick + ' 送出 ' + data.data_str.gift_name + ' x ' + data.data_str.num);
            setTimeout("$('#gifcontainer').hide()", 10000);
            break;
        case 'des_msg':

            if (globalgid == data.roomid) {
                des_msg = data.des_msg;
            }
            break;
        //更新机器人
        case 'set_robot':
            if (globalgid == data.roomid) {
                var OnlineUserNum = getId('OnlineUserNum');
                var RealUserNum = getId('RealUserNum').innerHTML;
                OnlineUserNum.innerHTML = parseInt(RealUserNum) + parseInt(data.robot_num);
            }
            break;
        //维护
        case 'MaxOnline':
            document.body.innerHTML = '<div  style="font-size:12px; text-align:center; top:100px; position:absolute;width:100%">O.O 对不起，服务端并发数已满！请您联系管理员对系统扩容升级！<br><br></div>';
            break;
        //充值
        case 'recharge':
            if (globalgid == data.roomid) {
                //充值
                My.diamond = parseInt(My.diamond)+parseInt(data.cost);
            }
            break;
        //踢人
        case 'kick':
            location.href = "error.php?msg=" + encodeURI('你被踢出！并禁止' + data.ktime + '分钟内登陆该房间！<br>原因是 ' + data.cause + '');
            break;
    }
}
// 输入姓名
function show_prompt(){
    // name = prompt('输入你的名字：', '');
    if(!name || name=='null'){
        name = '新人';
    }
}

// 提交对话
function onSubmit() {
    var input = document.getElementById("textarea");
    var to_client_id = $("#client_list option:selected").attr("value");
    var to_client_name = $("#client_list option:selected").text();
    ws.send('{"type":"say","to_client_id":"'+to_client_id+'","to_client_name":"'+to_client_name+'","content":"'+input.value.replace(/"/g, '\\"').replace(/\n/g,'\\n').replace(/\r/g, '\\r')+'"}');
    input.value = "";
    input.focus();
}

// 刷新用户列表框
function flush_client_list(){
    var onlineNum = client_list.length;
    for (i = 0; i < onlineNum; i++)
    {
        var U = client_list[i];
        if(U.chatid == '-1' || U.chatid == '-2')
            continue;
        UserList.add(U.chatid, U);
    }

    $("#client_list").val(select_client_id);
}

$(function(){
    select_client_id = 'all';
    $("#client_list").change(function(){
        select_client_id = $("#client_list option:selected").attr("value");
    });


});

